package org.zfes.snowier.cloud.zbss.layer.tc.biz.controller;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.core.data.ComboboVo;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.core.util.ZStrUtil;
import org.zfes.snowier.web.annos.ListParam;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.cloud.zbss.layer.tc.biz.model.Orgnization;
import org.zfes.snowier.cloud.zbss.layer.tc.biz.service.IOrgnizationService;
@Controller 
@RequestMapping("/tcms/orgnization")
public class OrgnizationController extends BaseController {

	private String viewPathPrefix="/tcms";
	
	@Autowired
	private IOrgnizationService orgnizationService;
	
	@RequestMapping(value={"/",""}, method = RequestMethod.GET,produces = MediaType.TEXT_HTML_VALUE)
    public Object index(){
		return forward(viewPathPrefix,"orgnization.html");
    }
	
	//@RequiresPermissions(value="orgnization:loadOrgnizationList",desc="单位列表")
    @RequestMapping(value="/loadOrgnizationDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadOrgnizationDataSet(@RequestParam Map<String,Object> params){
	    DataSet dataSet=  orgnizationService.loadOrgnizationDataSet(params);
	    return dataSet;
    }
	
	//@RequiresPermissions(value="orgnization:addOrgnization",desc="单位添加")
    @RequestMapping(value="/addOrgnization", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object addOrgnization(Orgnization orgnization){
		orgnizationService.createOrgnization(orgnization);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="orgnization:loadOrgnization",desc="单位加载")
    @RequestMapping(value="/loadOrgnization", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadOrgnization(Long id){
		Optional<Orgnization> ops = orgnizationService.loadOrgnizationById(id);
		return ajaxQuery("orgnization",ops);
    }
	
	//@RequiresPermissions(value="orgnization:updateOrgnization",desc="单位更新")
    @RequestMapping(value="/updateOrgnization", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateOrgnization(Orgnization orgnization){
		orgnizationService.updateOrgnization(orgnization);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
	//@RequiresPermissions(value="orgnization:deletOrgnization",desc="单位删除")
    @RequestMapping(value="/deletOrgnization", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object deletOrgnization(Long id){
		orgnizationService.deletOrgnization(id);
		return ajaxDoneSuccess("数据操作成功 ");
    }

    @RequestMapping(value="/loadOrgnizationComboboVo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadAuthAppComboboVo(Boolean firstEmpty ){
		 List<ComboboVo> appList=orgnizationService.loadComboboVo(firstEmpty);
		 return ajaxQuery("snowyselectdata", appList);
    }
    @RequestMapping(value="/setOrgnizationEnabled", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object setOrgnizationEnabled(@ListParam(Long.class)List<Long> ids,Boolean  enabled){
		orgnizationService.setOrgnizationEnabled(ids,enabled);
		return ajaxDoneSuccess("数据操作成功 ");
    }

}